/**
 * Created by Administrator on 2025/5/28.
 * */
#include "AIE2ETrainController.h"
#include <iostream>
#include <thread>

BaseObject *createAIE2ETrainController() {
    return new AIE2ETrainController();
}

void destroyAIE2ETrainController(BaseObject *p) {
    SAFE_DELETE(p);
}

AIE2ETrainController::AIE2ETrainController(){
}

AIE2ETrainController::~AIE2ETrainController() {
}

/* 如果使用了DDS_Reader或者DDS_Writer，则对应的input或者output前64个字节为DataFormat head首部 */
void AIE2ETrainController::onCompute(buffer_table_t *input, buffer_table_t *output) {
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));
    if (input->list[1]->valid) {
        int *pState = reinterpret_cast<int*>(input->list[1]->data);
        if (*pState > 0) {
            auto aiE2ENetStateHolder = GlobalParameters::shareInstance()->findParameter("aiE2ENetState");
            int *aiE2ENetState = static_cast<int*>(GlobalParameters::shareInstance()->getValue(aiE2ENetStateHolder, dynamic_cast<TaskModule*>(this)));
            *aiE2ENetState = *pState;
            std::cout << "AIE2ETrainController::onCompute port1 接收到状态更新：state=" << *pState << "; !!!!!!!!!!" << std::endl;
        }
    }
    if (input->list[2]->valid) {
        int *pAIE2ENetState = reinterpret_cast<int*>(input->list[2]->data);
        if (*pAIE2ENetState > 0) {
            auto aiE2ENetStateHolder = GlobalParameters::shareInstance()->findParameter("aiE2ENetState");
            int *aiE2ENetState = static_cast<int*>(GlobalParameters::shareInstance()->getValue(aiE2ENetStateHolder, dynamic_cast<TaskModule*>(this)));
            *aiE2ENetState = *pAIE2ENetState;
            std::cout << "AIE2ETrainController::onCompute port2 接收到状态更新：state=" << *pAIE2ENetState << "; !!!!!!!!!!" << std::endl;
        }
    }
}
